<?php
/**
 * 砍价次数Model
 *
 * Date: 2017/7/20
 * Time: 11:20
 */
defined('InNcPHP') or exit('Access Invalid!');

class bargain_countModel  extends  Model {


    public  function  __construct()
    {
        parent::__construct('bargain_count');
    }



    /**
     * @param array $condition
     * @param string $field
     * @param null $page
     * @param string $order
     * @return mixed
     */
    public function getCountPage($condition = array(), $field = '*', $page = null, $order = ''){

        return $this->table('bargain_count')->field($field)->where($condition)->page($page)->order($order)->select();

    }


    /**
     *
     * 修改
     */
    public function upcountdate($condition,$param)
    {
        return $this->table('bargain_count')->where($condition)->update($param);
    }

    /**
     * 判断是否第一次帮忙砍价
     * @param $member_id
     * @param $order_id
     */

    public function checkOnebargain($member_id,$order_id){
            $condition  = array();
            $condition['member_id'] = $member_id;
            $condition['bg_order_id'] = $order_id;
            $re = $this->where($condition)->find();
            if(empty($re)){
              return true;
            }else{
                return false;
            }

    }


    /**
     * 获取一条记录的详细信息
     * @param array $condition
     * @param string $field
     * @return mixed
     */
    public function getbargain_countInfo($condition = array(), $field = '*')
    {
        return $this->table('bargain_count')->field($field)->where($condition)->find();
    }

    /**
     * 获取帮忙的总人数
     * $order_id 订单ID
     */
    public  function  getBgargincount($order_id){

        $res = $this->where(array('bg_order_id'=>$order_id))->count();
        //$re  = $this->table('bargain_paid')->where(array('bargain_order_id'=>$order_id))->count();
        return $res;
    }
}